package com.edu.exam.enums.questionbank;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 题库状态枚举
 *
 * <p>管理题库的状态流程，包括草稿、启用、停用、已归档、锁定等状态。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum QuestionBankStatus implements BaseEnum {

    /**
     * 草稿
     */
    DRAFT("DRAFT", "草稿"),

    /**
     * 启用
     */
    ACTIVE("ACTIVE", "启用"),

    /**
     * 停用
     */
    INACTIVE("INACTIVE", "停用"),

    /**
     * 已归档
     */
    ARCHIVED("ARCHIVED", "已归档"),

    /**
     * 锁定
     */
    LOCKED("LOCKED", "锁定");

    private final String code;
    private final String description;

    QuestionBankStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static QuestionBankStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Question bank status code cannot be null or empty");
        }

        for (QuestionBankStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown question bank status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static QuestionBankStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Question bank status description cannot be null or empty");
        }

        for (QuestionBankStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown question bank status description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}